import { Card } from 'antd';
import { FormattedMessage } from 'umi';
import React,{ useRef } from 'react';
import ProTable, { ProColumns, ActionType } from '@ant-design/pro-table';
import { history } from 'umi';
import { TableListItem } from '../../../Plan/data.d';
import { planList } from '../service';
import styles from '../style.less';

interface PlanReviewRemnderProps {
  loading: boolean;
}
/**
 * 计划审核提醒
 * @param props 
 */
const PlanReviewReminder: React.FC<PlanReviewRemnderProps> = (props) => {

  const { loading } = props;

  const actionRef = useRef<ActionType>();

  const columns: ProColumns<TableListItem>[] = [
    {
      title: '序号',
      dataIndex: 'index',
      valueType: 'text',
      width:80,
    },
    {
      title: '计划名称',
      dataIndex: 'name',
      valueType: 'text',
      ellipsis: true,
      width:200,
    },
    {
      title: '审核状态',
      dataIndex: 'auditStatus',
      valueType: 'text',
      valueEnum: {
        0: { text: '待审核', status: 'Processing' },
      },
    },
    {
      title: '提交时间',
      dataIndex: 'updateDatetime',
      valueType: 'dateTime',
    },
    {
      title: '提交人',
      dataIndex: 'userNickname',
      valueType: 'text',
      hideInSearch: true, 
    },
    {
      title: '操作',
      dataIndex: 'option',
      valueType: 'option',
      render: (_, record) => (
        <>
          <a
            disabled = {localStorage.getItem("authority").indexOf("plan:audit") > -1?false:true}
            onClick={() => {
              history.push('/plan/review/');
            }}
          >
            {localStorage.getItem("authority").indexOf("plan:audit") > -1?"预览并审核":"暂无权限"}
          </a>
        </>
      ),
    },
  ];
  return (
      <Card
        loading={loading}
        className={styles.salesCard}
        bordered={false}
        title={
          <FormattedMessage
            id="dashboardanddashboardanalysis.analysis.plan-review-reminder"
            defaultMessage="The Review Reminder of Plan"
          />
        }
        style={{
          height: '100%',
        }}
      >
        <div>
        <ProTable<TableListItem>
          options={false}
          actionRef={actionRef}
          rowKey="key"
          search={false}
          pagination={{ showQuickJumper: true,defaultPageSize: 10 }}
          params={{"auditStatus":0}}
          request={(params, sorter, filter) => planList({ ...params, sorter, filter })}
          columns={columns}
        />
        </div>
      </Card>
  );
};

export default PlanReviewReminder;
